﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core;

namespace COFE.IO.SZ
{
    public static class SevenZip_IFileSystemInfoExAExtensions
    {
        public static bool IsFileBasedFS(this IInternalFileSystemInfoExA entry)
        {
            return (entry is IInternalDirectoryInfoExA && (entry as IInternalDirectoryInfoExA).IsFileBasedFS);
        }


        internal static IFileInfo GetEmbeddedArchive(this IInternalDirectoryInfoExA entry)
        {        
            if (entry.IsFileBasedFS())
                return entry.FileBasedFSFile;
            else throw new NotSupportedException("Entry is not a FileBasedFS");
        }


        internal static string GetRootParseName(this IInternalFileSystemInfoExA entry)
        {
            return entry.GetProperty(SevenZipFSIProperties.szfsiRootParseName).ValueAsString;
        }

        internal static string GetRootParseName(this IFileSystemInfo entry)
        {
            return (entry as IInternalFileSystemInfoExA).GetRootParseName();
        }

        internal static string GetRelativePath(this IInternalFileSystemInfoExA entry)
        {
            return entry.GetProperty(SevenZipFSIProperties.szfsiRelativePath).ValueAsString;
        }

        internal static string GetRelativePath(this IFileSystemInfo entry)
        {
            return (entry as IInternalFileSystemInfoExA).GetRelativePath();
        }

        internal static string GetParentRelativePath(this IInternalFileSystemInfoExA entry)
        {
            if (entry is IInternalDirectoryInfoExA && entry.IsFileBasedFS())
                return (entry as IInternalDirectoryInfoExA).GetEmbeddedArchive().GetRelativePath();
            return (entry as IInternalFileSystemInfoExA).GetRelativePath();
        }

    }
}
